#ifndef TCP_SERVER_H
#define TCP_SERVER_H

#include "EventPool.h"

using std::function;

class TcpServer
{
    using TcpConnectPtr = shared_ptr<TcpConnect>;
    using callback = function<void(TcpConnectPtr)>;

private:
    Acceptor _acceptor;
    EventPool _loop;

public:
    TcpServer(const char *ip, unsigned short port)
        : _acceptor{ip, port}, _loop{_acceptor}
    {
    }

    void start()
    {
        _acceptor.init();
        _loop.loop();
    }

    void stop()
    {
        _loop.unloop();
    }

    void setCallback(callback &&onConnect, callback &&onMessage, callback &&onClose)
    {
        _loop.setConnectCallback(std::move(onConnect));
        _loop.setMessageCallback(std::move(onMessage));
        _loop.setClosedCallback(std::move(onClose));
    }
};

#endif